(() => {
    function init() {
        checkUser();
    }

    function cimg() {
        var img = document.getElementById("img");
        var fil = document.getElementById("file");
        //读取文件
        var file = fil.files[0];
        var fr = new FileReader();
        fr.onloadend = function(e) {
                //把图片加载到标签上
                img.src = e.target.result;
            }
            //以数据流的方式 读取图片
        fr.readAsDataURL(file);
    }

    function checkUser() {
        const tips = document.querySelector('#tips');
        const user = document.querySelector('#name');
        user.onchange = () => {
            const cont = user.value;
            console.log(cont)
            ajax({
                url: './control/checkUser.php',
                method: 'GET',
                data: {
                    value: cont
                },
                sussces: res => {
                    if (res === '0') {
                        tips.innerHTML = '可以注册';
                        tips.style.color = 'green';
                        document.querySelector('.subBtn').disabled = false;
                        user.style.color = '#000';
                    } else {
                        tips.innerHTML = '用户名存在';
                        tips.style.color = 'red';
                        document.querySelector('.subBtn').disabled = true;
                        user.style.color = 'rgba(128, 128, 128, 0.9)';
                    }
                }
            })
        }
    }

    init();
})();